/**
 * Copyright (c) 2020 xstgongyi.org
 * All rights reserved.
 */
package org.xstgongyi.eduaid.manager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.xstgongyi.eduaid.bo.ProjectPhaseStatus;
import org.xstgongyi.eduaid.dao.ProjectPhaseMapper;
import org.xstgongyi.eduaid.dataobject.ProjectPhaseDO;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 缓存管理
 *
 * @author oldcrane
 * @created 2020-10-12
 */
@Service
@CacheConfig(cacheNames = "project-phase")
public class ProjectPhaseManager {

    @Autowired
    private ProjectPhaseMapper dao;

    @Cacheable(key = "'list-project-' + #projectId")
    public List<ProjectPhaseDO> listByProject(Integer projectId) {
        return dao.listByProject(projectId);
    }

    @Cacheable(key = "#id")
    public ProjectPhaseDO getById(Integer id) {
        return dao.getById(id);
    }

    // not cached
    public List<ProjectPhaseDO> list(Map<String, Object> condition) {
        return dao.list(condition);
    }

    @CacheEvict(allEntries = true)
    public int insert(ProjectPhaseDO projectPhase) {
        return dao.insert(projectPhase);
    }

    @CacheEvict(allEntries = true)
    public int updateStatus(Integer id, ProjectPhaseStatus status, LocalDateTime gmtUpdated) {
        return dao.updateStatus(id, status, gmtUpdated);
    }

}
